
import 'dart:io';

import 'package:path_provider/path_provider.dart';

import 'log_util.dart';

class FileUtil{
  //获取文件名
  static String getFileName({String? filePath}){
    if(filePath==null)return'';
    List<String> filePaths = filePath.split('/');
    if(filePaths.length==0){
      return '';
    }else if(filePaths.length<2){
      return filePaths[0];
    }else{
      return filePaths[filePaths.length-1];
    }
  }

  //获取文件前缀
  static String getFileNamePreSuffix({String? fileName}){
    if(fileName==null)return'';
    List<String> filePaths = fileName.split('.');
    if(filePaths.length==0){
      return '';
    }else if(filePaths.length<2){
      return filePaths[0];
    }else{
      return filePaths[0];
    }
  }
  //获取文件后缀
  static String getFileNameSuffix({String? filePath}){
    if(filePath==null)return'';
    List<String> filePaths = filePath.split('.');
    if(filePaths.length==0){
      return '';
    }else if(filePaths.length<2){
      return filePaths[0];
    }else{
      return filePaths[filePaths.length-1];
    }
  }
  //获取存储文件夹
  static Future<String> getDirectory({String? directoryName}) async{
    Directory _path = await getApplicationDocumentsDirectory();
    String _localPath = _path.path + Platform.pathSeparator +(directoryName??'');
    return _localPath;
  }

}
